package com.briup.day27;

import com.briup.day27.bean.Student;

import java.lang.reflect.Field;

public class Test_SetGet {
    public static void main(String[] args) throws Exception {
        Class<?> clazz = Class.forName("com.briup.day27.bean.Student");
        //获取指定的属性
        Field f1 = clazz.getField("id");
        System.out.println(f1);
        //获取属性对应的值依赖于普通对象
        Student s1 = new Student("001","terry",10);
        String id =(String) f1.get(s1);//f1是属性 属性.get获取对应的值
        System.out.println("---------------------");
        f1.set(s1,"002");
        System.out.println("修改后的属性对象: "+s1);
        System.out.println("---------------------");
        //获取指定的private属性
        Field f2 = clazz.getDeclaredField("name");
        f2.setAccessible(true);
        String s2 = (String) f2.get(s1);
        System.out.println("获取私有属性name"+s2);
        f2.set(s1,"vwvwviwiw");
        System.out.println("修改后的S1name"+s1);

    }
}
